<template>
  <a-card
    :title="title"
    v-if="currentRates.length">
    <a-card-grid
      style="width: 20%;height: 80px; text-align: center"
      :hoverable="false">序号</a-card-grid>
    <!-- <a-card-grid
      style="width: 20%;height: 80px;text-align: center"
      :hoverable="false">组成</a-card-grid> -->
    <a-card-grid
      style="width: 60%;height: 80px; text-align: center"
      :hoverable="false">发放条件</a-card-grid>
    <a-card-grid
      style="width: 20%;height: 80px; text-align: center"
      :hoverable="false">发放标准</a-card-grid>
    <template v-for="i in count">
      <a-card-grid
        :key="`${i}_1`"
        style="width: 20%;height: 80px; text-align: center"
        :hoverable="false">{{ i }}</a-card-grid>
      <!-- <a-card-grid
        :key="`${i}_2`"
        style="width: 20%;height: 80px;text-align: center"
        :hoverable="false">
        <div>
          <span>{{ i }}</span>
        </div>
      </a-card-grid> -->
      <a-card-grid
        :key="`${i}_3`"
        style="width: 60%;height: 80px; text-align: center"
        :hoverable="false">
        <div>
          <!-- <div
            v-show="edit"
            style="left: -10px; width: 100%; top: -10px;text-align: left;">
            <a-input-number
              v-if="currentMarks[i - 1]"
              v-model="currentMarks[i - 1]"
              placeholder="请输入该备注" />
          </div> -->
          <span>{{ marks[i - 1] }}</span>
        </div>
      </a-card-grid>
      <a-card-grid
        :key="`${i}_5`"
        style="width: 20%;height: 80px; text-align: center"
        :hoverable="false">
        <div>
          <div
            v-show="edit"
            style="left: -10px; width: 100%; top: -10px;text-align: left;">
            <a-input-number
              :min="0"
              :max="100"
              :precision="2"
              v-model="currentRates[i - 1]"
              placeholder="请输入固定比率(%)" />
          </div>
          <span v-show="!edit">{{ showRate(rates[i - 1] ? rates[i - 1] * 100 : undefined) }}</span>
        </div>
      </a-card-grid>
    </template>
  </a-card>
</template>
<script>
import { showRate } from './config'

export default {
  name: 'ProdBonus',
  components: {},
  props: {
    title: {
      type: String,
      default: () => ''
    },
    count: {
      type: [Number, String],
      default: () => ''
    },
    rates: {
      type: Array,
      default: () => []
    },
    marks: {
      type: Array,
      default: () => []
    },
    edit: {
      type: Boolean,
      default: () => false
    }
  },
  watch: {
    edit: function (edit) {
      if (edit) {
        // this.currentMarks = this.marks.slice(0)
        this.currentRates = this.rates.slice(0).map(item => item ? (item * 100).toFixed(6) : undefined)
      }
    }
  },
  mounted () {
    // this.currentMarks = this.marks.slice(0)
    this.currentRates = this.rates.slice(0)
  },
  data () {
    this.showRate = showRate
    return {
      currentRates: []
      // currentMarks: []
    }
  },
  methods: {
    getValue () {
      /**
       * marks 发放条件
       * rates 发放标准
       */
      return {
        // marks: this.currentMarks,
        rates: this.currentRates.map(item => item ? (item / 100).toFixed(6) : undefined),
        count: 3
      }
    }
  }
}
</script>
